//
//  XMNavigationController.m
//  XM
//
//  Created by mingyue on 2017/12/18.
//  Copyright © 2017年 mingyue. All rights reserved.
//

#import "XMNavigationController.h"

@interface XMNavigationController ()<UINavigationControllerDelegate>
@property (nonatomic, strong) id popDelegate;

@end

@implementation XMNavigationController

/*
 + (void)initialize {
 //    //设置为不透明
 //    [[UINavigationBar appearance] setTranslucent:NO];
 //    //设置导航栏背景颜色
 //    [UINavigationBar appearance].barTintColor = NaviTintColor;
 //    //设置导航栏标题颜色和字体大小
 //    NSMutableDictionary * color = [NSMutableDictionary dictionary];
 //    color[NSFontAttributeName] = [UIFont systemFontOfSize:17.0];
 //    color[NSForegroundColorAttributeName] = [UIColor whiteColor];;
 //    [[UINavigationBar appearance] setTitleTextAttributes:color];
 //
 //    [[UINavigationBar appearance] setShadowImage:[UIImage new]];
 //    [[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
 }
 */

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _popDelegate = self.interactivePopGestureRecognizer.delegate;
    self.delegate = self;
}

#pragma mark - 'delegate'
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count) {
        //如果在堆栈控制器数量大于1 加返回按钮,隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
        //        UIBarButtonItem *backItem = [UIBarButtonItem barButtonItemWithImage:nil
        //                                                                  highImage:nil
        //                                                                     target:self
        //                                                                     action:@selector(popToPre)
        //                                                           forControlEvents:UIControlEventTouchUpInside];
        //        self.navigationItem.leftBarButtonItem = backItem;
        
    }
    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    
    if (viewController == self.viewControllers[0]) {
        // 是根控制器
        self.interactivePopGestureRecognizer.delegate = nil;
        
    }else{
        // 非根控制器
        self.interactivePopGestureRecognizer.delegate = _popDelegate;
        
    }
}

- (void)popToPre
{
    [self popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end

